package com.lagou.config;

import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator;
import org.apache.shardingsphere.core.strategy.keygen.UUIDShardingKeyGenerator;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;

import java.util.Properties;

/**
 *
 * ID生成器内置了2个, 通过SPI注入
 * @author zy.du
 * @date 2020/9/29 3:22 PM
 */
public class CustomSnowflakeId implements ShardingKeyGenerator {

    private UUIDShardingKeyGenerator uuidShardingKeyGenerator = new UUIDShardingKeyGenerator();
    private SnowflakeShardingKeyGenerator snowflakeShardingKeyGenerator = new SnowflakeShardingKeyGenerator();

    @Override
    public Comparable<?> generateKey() {
        return snowflakeShardingKeyGenerator.generateKey(); //uuidShardingKeyGenerator.generateKey();
    }

    @Override
    public String getType() {
        return "CUSTOM_KEY";
    }

    @Override
    public Properties getProperties() {
        return null;
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
